
from flask import Flask, url_for, request
from markupsafe import escape

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'hello world'

@app.route('/user/<username>')
def show_user_profile(username):
    return f'User {escape(username)}'

@app.route('/user/<float:postId>')
def show_userPost(postId):
    return f'Post {postId}'

@app.route('/projects')
def projects():
    return 'The project page'
@app.route('/about')
def about():
    return 'The about page'

# with app.test_request_context():
#     # print(url_for('index'))
#     print(url_for('login',next='/'))
#     print(url_for('profile',username='John Doe'))

@app.route('/hello', methods=['GET', 'POST'])
def hello():
    return 'Hello, World!'
@app.route('/hi', methods=['POST'])
def hi():
    return 'Hi, World!'

@app.route('/getinfo', methods=['GET'])
def getInfo():
    return request.args.get('info')

@app.route('/removeUser/<int:userid>', methods=['DELETE'])
def deleteUser(userid):
    return f'remove user: {userid}'



@app.route('/register', methods=['POST'])
def register():
    print(request.headers)
    print(request.stream.read())
    print( 'form: ', request.form )
    # print('request', request.form['name'])
    return 'Hi, World!'

@app.route('/test')
def testUrl():
    # print(url_for('hello'))
    print(url_for('user_page', name='peter'))
    return 'Hi, World!'

if __name__=='__main__':
    app.run()
